//package org.blackcat.dao.mongo;
//
//import com.mongodb.MongoClient;
//import com.mongodb.MongoClientOptions;
//import com.mongodb.MongoCredential;
//import com.mongodb.ServerAddress;
//import com.mongodb.client.MongoDatabase;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.Arrays;
//
//
///**
// * Created by Duo Duo on 2017/1/10.
// */
////@Component
//public final class MongoManager {
//
//    @Autowired
//    private MongoConfig mongoConfig;
//
//    //认证
//    private MongoCredential credential = MongoCredential.createCredential(mongoConfig.getUser(),mongoConfig.getDatabase(),mongoConfig.getPassword().toCharArray());
//
//    //创建实例
//    private  MongoClient mongoClient = new MongoClient(new ServerAddress(mongoConfig.getHost(),mongoConfig.getPort()),
//            Arrays.asList(credential),getBuilder());
//
//    //获取客户端
//    public final MongoClient getMongoClient(){
//        return mongoClient;
//    }
//
//    //获取默认数据库
//    public final MongoDatabase getMongoDefaultDB(){
//        return mongoClient.getDatabase("graduation");
//    }
//
//    //配置连接池
//    private MongoClientOptions getBuilder(){
//        MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
//        //与数据最大连接数
//        builder.connectionsPerHost(mongoConfig.getMaxActive());
//        builder.threadsAllowedToBlockForConnectionMultiplier(mongoConfig.getThreadsAllowedToBlock());
//        builder.connectTimeout(mongoConfig.getTimeout());
//        builder.maxWaitTime(mongoConfig.getMaxWaitTime());
//        return builder.build();
//    }
//
//}
